from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-07-19 14:03:30.009132
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Tue, 19, Jul, 2022
Time: 14:03:36
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.8498
Nobs: 722.000 HQIC: -50.2005
Log likelihood: 9071.71 FPE: 1.26605e-22
AIC: -50.4210 Det(Omega_mle): 1.11863e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.299526 0.057023 5.253 0.000
L1.Burgenland 0.106973 0.037362 2.863 0.004
L1.Kärnten -0.107097 0.019811 -5.406 0.000
L1.Niederösterreich 0.210611 0.078283 2.690 0.007
L1.Oberösterreich 0.106542 0.076412 1.394 0.163
L1.Salzburg 0.253803 0.039976 6.349 0.000
L1.Steiermark 0.042133 0.052167 0.808 0.419
L1.Tirol 0.108681 0.042295 2.570 0.010
L1.Vorarlberg -0.063615 0.036537 -1.741 0.082
L1.Wien 0.047665 0.067536 0.706 0.480
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.054715 0.119164 0.459 0.646
L1.Burgenland -0.031299 0.078077 -0.401 0.689
L1.Kärnten 0.046973 0.041400 1.135 0.257
L1.Niederösterreich -0.178712 0.163592 -1.092 0.275
L1.Oberösterreich 0.412429 0.159681 2.583 0.010
L1.Salzburg 0.288674 0.083540 3.456 0.001
L1.Steiermark 0.106879 0.109015 0.980 0.327
L1.Tirol 0.311813 0.088386 3.528 0.000
L1.Vorarlberg 0.026409 0.076353 0.346 0.729
L1.Wien -0.030779 0.141134 -0.218 0.827
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.188251 0.029130 6.462 0.000
L1.Burgenland 0.089935 0.019086 4.712 0.000
L1.Kärnten -0.008854 0.010120 -0.875 0.382
L1.Niederösterreich 0.262989 0.039990 6.576 0.000
L1.Oberösterreich 0.137771 0.039034 3.529 0.000
L1.Salzburg 0.046206 0.020421 2.263 0.024
L1.Steiermark 0.020089 0.026649 0.754 0.451
L1.Tirol 0.092707 0.021606 4.291 0.000
L1.Vorarlberg 0.056524 0.018665 3.028 0.002
L1.Wien 0.115549 0.034500 3.349 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.111303 0.029647 3.754 0.000
L1.Burgenland 0.045346 0.019425 2.334 0.020
L1.Kärnten -0.013917 0.010300 -1.351 0.177
L1.Niederösterreich 0.190580 0.040700 4.683 0.000
L1.Oberösterreich 0.301956 0.039727 7.601 0.000
L1.Salzburg 0.109586 0.020784 5.273 0.000
L1.Steiermark 0.104060 0.027122 3.837 0.000
L1.Tirol 0.105067 0.021990 4.778 0.000
L1.Vorarlberg 0.067473 0.018996 3.552 0.000
L1.Wien -0.021970 0.035113 -0.626 0.532
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.130387 0.054052 2.412 0.016
L1.Burgenland -0.050251 0.035415 -1.419 0.156
L1.Kärnten -0.040977 0.018779 -2.182 0.029
L1.Niederösterreich 0.166864 0.074204 2.249 0.025
L1.Oberösterreich 0.141928 0.072430 1.960 0.050
L1.Salzburg 0.289098 0.037893 7.629 0.000
L1.Steiermark 0.035427 0.049448 0.716 0.474
L1.Tirol 0.162956 0.040091 4.065 0.000
L1.Vorarlberg 0.098430 0.034633 2.842 0.004
L1.Wien 0.068485 0.064017 1.070 0.285
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.055856 0.043027 1.298 0.194
L1.Burgenland 0.039331 0.028191 1.395 0.163
L1.Kärnten 0.051367 0.014948 3.436 0.001
L1.Niederösterreich 0.217001 0.059069 3.674 0.000
L1.Oberösterreich 0.295846 0.057657 5.131 0.000
L1.Salzburg 0.043726 0.030164 1.450 0.147
L1.Steiermark 0.001375 0.039363 0.035 0.972
L1.Tirol 0.142367 0.031914 4.461 0.000
L1.Vorarlberg 0.072614 0.027569 2.634 0.008
L1.Wien 0.081369 0.050960 1.597 0.110
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.175471 0.051443 3.411 0.001
L1.Burgenland -0.002776 0.033705 -0.082 0.934
L1.Kärnten -0.062598 0.017872 -3.503 0.000
L1.Niederösterreich -0.082508 0.070622 -1.168 0.243
L1.Oberösterreich 0.193721 0.068934 2.810 0.005
L1.Salzburg 0.057604 0.036064 1.597 0.110
L1.Steiermark 0.235555 0.047061 5.005 0.000
L1.Tirol 0.497615 0.038156 13.042 0.000
L1.Vorarlberg 0.043621 0.032961 1.323 0.186
L1.Wien -0.053268 0.060927 -0.874 0.382
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.174136 0.058987 2.952 0.003
L1.Burgenland -0.007248 0.038649 -0.188 0.851
L1.Kärnten 0.066300 0.020493 3.235 0.001
L1.Niederösterreich 0.209201 0.080979 2.583 0.010
L1.Oberösterreich -0.075042 0.079043 -0.949 0.342
L1.Salzburg 0.207595 0.041353 5.020 0.000
L1.Steiermark 0.122292 0.053963 2.266 0.023
L1.Tirol 0.070483 0.043752 1.611 0.107
L1.Vorarlberg 0.115447 0.037796 3.055 0.002
L1.Wien 0.119320 0.069862 1.708 0.088
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.361828 0.034006 10.640 0.000
L1.Burgenland 0.007078 0.022281 0.318 0.751
L1.Kärnten -0.023927 0.011814 -2.025 0.043
L1.Niederösterreich 0.217300 0.046685 4.655 0.000
L1.Oberösterreich 0.199752 0.045568 4.384 0.000
L1.Salzburg 0.043068 0.023840 1.807 0.071
L1.Steiermark -0.014722 0.031110 -0.473 0.636
L1.Tirol 0.105166 0.025223 4.169 0.000
L1.Vorarlberg 0.070402 0.021789 3.231 0.001
L1.Wien 0.036141 0.040275 0.897 0.370
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.040162 0.138326 0.190733 0.150679 0.117367 0.102677 0.061701 0.215831
Kärnten 0.040162 1.000000 -0.006382 0.132951 0.039259 0.094586 0.433795 -0.053398 0.098048
Niederösterreich 0.138326 -0.006382 1.000000 0.335194 0.140285 0.294597 0.095121 0.175463 0.313755
Oberösterreich 0.190733 0.132951 0.335194 1.000000 0.226274 0.325117 0.172871 0.163015 0.261461
Salzburg 0.150679 0.039259 0.140285 0.226274 1.000000 0.142300 0.110924 0.143799 0.122983
Steiermark 0.117367 0.094586 0.294597 0.325117 0.142300 1.000000 0.145693 0.136701 0.071011
Tirol 0.102677 0.433795 0.095121 0.172871 0.110924 0.145693 1.000000 0.110981 0.141955
Vorarlberg 0.061701 -0.053398 0.175463 0.163015 0.143799 0.136701 0.110981 1.000000 -0.001975
Wien 0.215831 0.098048 0.313755 0.261461 0.122983 0.071011 0.141955 -0.001975 1.000000